package br.nextfm.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.nextfm.dao.ArtistaDao;
import br.nextfm.model.Artista;

public class CadastraArtistaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String nome = request.getParameter("nome");
		String descricao = request.getParameter("descricao");
		String tags = request.getParameter("tags");
		String imagem = request.getParameter("foto");
		
		Artista artista = new Artista(nome, descricao, imagem, tags);
		ArtistaDao dao = new ArtistaDao();
		
		if (!dao.insert(artista)) {
			
			request.setAttribute("erroCadastraArtista", true);
			
		}
		
		request.setAttribute("artistas", dao.getAll());
		request.getRequestDispatcher("artista.jsp").forward(request, response);
		
	}

}
